package com.larry.tinyweb.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class DateUtil {

	private static String FORMAT = "yyyy-MM-dd HH:mm:ss";

	public static String getTime() {
		return getTime(new Date(), FORMAT);
	}

	public static String getTime(Date date) {
		SimpleDateFormat sf = new SimpleDateFormat(FORMAT);
		return sf.format(date);
	}

	public static String getTime(Date date, String format) {
		if (format == null || "".equals(format)) return getTime(date);

		SimpleDateFormat sf = new SimpleDateFormat(format);
		return sf.format(date);
	}

	public static String getTime(String format) {
		return getTime(new Date(), format);
	}

	public static Date toDate(String time) throws ParseException {
		SimpleDateFormat sf = new SimpleDateFormat(FORMAT);
		return sf.parse(time);
	}

}
